import {
  getToplist,
  getToplistDetail
} from '@/services/toplist-api'
import * as actionTypes from './constants'
const changeToplistAction = toplist => ({
  type: actionTypes.CHANGE_TOPLIST_ACTION,
  toplist
})
export const getToplistAction = () => {
  return async dispatch => {
    const res = await getToplist()
    console.log(res.list);
    dispatch(changeToplistAction(res.list))
  }
}
const changeCurrentToplistDetailAction = currentToplistDetail => ({
  type: actionTypes.CHANGE_CURRENT_TOPLIST_DETAIL,
  currentToplistDetail
})
export const getCurrentToplistDetailAction = id => {
  return async dispatch => {
    const res = await getToplistDetail(id)
    console.log(res.playlist);
    dispatch(changeCurrentToplistDetailAction(res.playlist))
  }
}
const changeCurrentIndexAction = currentIndex => ({
  type: actionTypes.CHANGE_CURRENT_INDEX_ACTION,
  currentIndex
})
export const getCurrentIndexAction = index => {
  return dispatch => {
    dispatch(changeCurrentIndexAction(index))
  }
}